package com.gw.crm.utils;

import org.dromara.easyai.entity.ThreeChannelMatrix;
import org.dromara.easyai.matrixTools.Matrix;
import org.dromara.easyai.matrixTools.MatrixOperation;
import org.dromara.easyai.tools.ImageTools;
import org.dromara.easyai.tools.Picture;

import java.util.Random;


public class EasyAiUtils {
    public static void main(String[] args) throws Exception{
        Random random = new Random();
        modifyLocalColor("D:\\Other\\easyai\\testPic\\a1.jpg", random);
    }

    public static void modifyLocalColor(String pictureURL, Random random) throws Exception {//
        MatrixOperation matrixOperation = new MatrixOperation();
        // 获取图片三通道
        ThreeChannelMatrix ch = Picture.getThreeMatrix(pictureURL,false);
        float minRf = 1 - 0.1f * 0.2f;
        float maxRf = 1 + 0.1f * 0.2f;
        float factor;
        if (random.nextBoolean()) {
            factor = minRf;
        } else {
            factor = maxRf;
        }
        Matrix matrixR = ch.getMatrixR();
        Matrix matrixG = ch.getMatrixG();
        Matrix matrixB = ch.getMatrixB();

        matrixOperation.mathMul(matrixR, factor);
        matrixOperation.mathMul(matrixG, factor);
        matrixOperation.mathMul(matrixB, factor);

        ch.setMatrixB(matrixB);
        ch.setMatrixG(matrixG);
        ch.setMatrixR(matrixR);


        ImageTools.writeImage(ch,"D:\\Other\\easyai\\testPic\\t12.jpg");
    }
}
